/*
*  SkyDecoder.cpp
*  
*
*  Created by Alexander Trutchenko on 11/02/12.
*  Copyright 2012 Free Team. All rights reserved.
*
*/

#include "SkyDecoder.h"

#include "SkyBufferManager.h"
#include "SkyConfig.h"


#if (SKY_TARGET_PLATFORM == SKY_PLATFORM_WIN32)

#include "SkyALUTDecoder.h"
#include "SkyDecoderOGGwin32.h"

#endif  // CC_PLATFORM_WIN32

#if (SKY_TARGET_PLATFORM == SKY_PLATFORM_BADA)
#endif  // SKY_PLATFORM_BADA

#if (SKY_TARGET_PLATFORM == SKY_PLATFORM_IOS)
#endif  // SKY_PLATFORM_IOS

namespace sky {

void addDecoders(SkyBufferManager* bufManager)
{
#if (SKY_TARGET_PLATFORM == SKY_PLATFORM_WIN32)

//Static decoders
	bufManager->addStaticDecoder(new SkyALUTStaticDecoder());
	bufManager->addStaticDecoder(new SkyOGGStaticDecoder());

//Stream decoders
	bufManager->addStreamDecoderFactoryForKey(new SkyOGGStreamDecoderFactory(), SKY_OGG_DECODED_EXT);

#endif  // CC_PLATFORM_WIN32



}


////////////////////////////////////////////////////////
//
/** SkyStreamFileData
*  
*/
////////////////////////////////////////////////////////

SkyStreamFileData::SkyStreamFileData(SkyBufferManager* bufferManager, const SkyFileData* fileData)
: SkyStreamData(bufferManager, fileData->file())
, _fileData(fileData)
, _dataCursor(0)
, _playbackCursor(0.f)
{
	if (_fileData == NULL)
	{
		_isValid = false;
		return;
	}
	if (_bufferManager != NULL)
		_bufferManager->preloadCompressedFile(_fileData->file());
}

SkyStreamFileData::SkyStreamFileData(SkyBufferManager* bufferManager, const char* file)
: SkyStreamData(bufferManager, file)
, _fileData(NULL)
, _dataCursor(0)
, _playbackCursor(0.f)
{
	_fileData = _bufferManager->preloadCompressedFile(file);
	if (_fileData == NULL)
	{
		_isValid = false;
		return;
	}
}

SkyStreamFileData::~SkyStreamFileData()
{
	if (_fileData != NULL && _bufferManager != NULL)
		_bufferManager->unloadCompressedFile(_fileData->file());
}

} // namespace sky
